package com.landi.carkey.util;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description {具体做什么}
 * @Creator wushan
 * @Date 2016/12/28 16:26
 */

public class StringUtil {

    /**
     * 判断电话号码是否可用
     *
     * @param PhoneNo
     * @return
     */
    public static boolean isValidPhoneNo(String PhoneNo) {
        if (TextUtils.isEmpty(PhoneNo))
            return false;

        if (PhoneNo.length() != 11) {
            return false;
        }

        String s = PhoneNo.substring(0,2);
        if (s.equals("13")||s.equals("14")||s.equals("15")||s.equals("17")||s.equals("18")){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 判断邮箱是否合法
     * @param email
     * @return
     */
    public static boolean isEmail(String email){
        if (null==email || "".equals(email)) return false;
        //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
        Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配
        Matcher m = p.matcher(email);
        return m.matches();
    }
}
